package qlsl.androiddesign.view.subview.activityview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import qlsl.androiddesign.activity.subactivity.CarTypeSecondActivity;
import qlsl.androiddesign.adapter.subadapter.PublishTypeSecondAdapter;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 评估二级分类页<br/>
 * 需要传入的键：title,position<br/>
 * 传入的值类型： String，int<br/>
 * 传入的值含义：标题，位置<br/>
 * 是否必传 ：是
 */
public class CarTypeSecondView extends FunctionView<CarTypeSecondActivity> {

	private ListView listView;

	public CarTypeSecondView(CarTypeSecondActivity activity) {
		super(activity);
		setContentView(R.layout.activity_publish_type_second);
	}

	protected void initView(View view) {
		setTitle(activity.getIntent().getStringExtra("title"));
		listView = findViewById(R.id.listView);
	}

	protected void initData() {
		setListViewData();
	}

	protected void initListener() {

	}

	public <T> void showData(T... t) {

	}

	public <T> void showNoData(T... t) {

	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.list_item:
			doClickListItem(view);
			break;
		}
	}

	@SuppressWarnings("unchecked")
	private void doClickListItem(View view) {
		int clickPosition = listView.getPositionForView(view);
		HashMap<String, Object> map = (HashMap<String, Object>) listView.getAdapter().getItem(clickPosition);
		Intent intent = new Intent();
		intent.putExtra("text", (String) map.get("text"));
		activity.setResult(0, intent);
		activity.finish();
	}

	private void setListViewData() {
		String[] descs_text_0 = new String[] { "日立" };
		String[] descs_text_1 = new String[] { "大宇" };

		List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		int position = activity.getIntent().getIntExtra("position", 0);
		String[] texts = null;
		if (position == 0) {
			texts = descs_text_0;
		} else if (position == 1) {
			texts = descs_text_1;
		}
		for (int index = 0; index < texts.length; index++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("text", texts[index]);
			list.add(map);
		}
		PublishTypeSecondAdapter adapter = new PublishTypeSecondAdapter(activity, list);
		listView.setAdapter(adapter);

	}

}
